package com.ruoyi.web.controller.xxc;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.news.domain.XcxNewComment;
import com.ruoyi.news.service.IXcxNewCommentService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 资讯评论Controller
 * 
 * @author ruoyi
 * @date 2024-12-02
 */
@RestController
@RequestMapping("/xcx/comment")
public class XcxNewCommentController extends BaseController
{
    @Autowired
    private IXcxNewCommentService xcxNewCommentService;

    /**
     * 查询资讯评论列表
     */
    @GetMapping("/list")
    public TableDataInfo list(XcxNewComment xcxNewComment)
    {
        startPage();
        List<XcxNewComment> list = xcxNewCommentService.selectXcxNewCommentList(xcxNewComment);
        return getDataTable(list);
    }

    /**
     * 导出资讯评论列表
     */
    @Log(title = "资讯评论", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, XcxNewComment xcxNewComment)
    {
        List<XcxNewComment> list = xcxNewCommentService.selectXcxNewCommentList(xcxNewComment);
        ExcelUtil<XcxNewComment> util = new ExcelUtil<XcxNewComment>(XcxNewComment.class);
        util.exportExcel(response, list, "资讯评论数据");
    }

    /**
     * 获取资讯评论详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(xcxNewCommentService.selectXcxNewCommentById(id));
    }

    /**
     * 新增资讯评论
     */
    @Log(title = "资讯评论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody XcxNewComment xcxNewComment, @AuthenticationPrincipal UserDetails user)
    {
        LoginUser loginUser =  (LoginUser)user;
        SysUser sysUser = loginUser.getUser();
        xcxNewComment.setCreateBy(sysUser.getUserId()+"");
        xcxNewComment.setId(IdUtils.fastSimpleUUID());

        return toAjax(xcxNewCommentService.insertXcxNewComment(xcxNewComment));
    }

    /**
     * 修改资讯评论
     */
    @Log(title = "资讯评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody XcxNewComment xcxNewComment)
    {
        return toAjax(xcxNewCommentService.updateXcxNewComment(xcxNewComment));
    }

    /**
     * 删除资讯评论
     */
    @Log(title = "资讯评论", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(xcxNewCommentService.deleteXcxNewCommentByIds(ids));
    }
}
